*************************************************************************
*																		*
*					Campaign Panel Book Chapter 5 - Communication Variables			*
*																		*
*************************************************************************	


use "${data}\ZA5305_en_v5-0-0.dta", clear

**************************************************************************
*			Reception of the TV-Debate yes/no			 						*
*																		*
**************************************************************************

fre kp?_1800*
// Only respondents who did not participate in W5 received this question at a 
// later time

* Nobody could have seen the debate before wave 5
foreach welle of numlist 1/5 {
gen watcheddebate`welle' = 0 
}

gen watcheddebate6 = 0 if kp6_1800==3
replace watcheddebate6 = 1 if kp6_1800==1 | kp6_1800==2

tab watcheddebate6 kp6_1800

* 
* Insert the same value after the event
gen watcheddebate7 = watcheddebate6





********************************************************************************
**
** Consumption of print media
**
********************************************************************************

tab1 kp3_1660* 
tab1 kp3_1660* , nolabel


// Bild

foreach welle of numlist 1 {
   recode kp`welle'_1720a (9/102=.), gen(pr_bild`welle')
   replace pr_bild`welle' = (pr_bild`welle'-1)/7
}

foreach welle of numlist 2/7 {
   recode kp`welle'_1660a (9/102=.), gen(pr_bild`welle')
   replace pr_bild`welle' = (pr_bild`welle'-1)/7
}

// Frankfurter Rundschau

foreach welle of numlist 1 {
   recode kp`welle'_1720b (9/102=.), gen(pr_fr`welle')
   replace pr_fr`welle' = (pr_fr`welle'-1)/7
}

foreach welle of numlist 2/7 {
   recode kp`welle'_1660b (9/102=.), gen(pr_fr`welle')
   replace pr_fr`welle' = (pr_fr`welle'-1)/7
}

// FAZ

foreach welle of numlist 1 {
   recode kp`welle'_1720c (9/102=.), gen(pr_faz`welle')
   replace pr_faz`welle' = (pr_faz`welle'-1)/7
}

foreach welle of numlist 2/7 {
   recode kp`welle'_1660c (9/102=.), gen(pr_faz`welle')
   replace pr_faz`welle' = (pr_faz`welle'-1)/7
}


// SZ

foreach welle of numlist 1 {
   recode kp`welle'_1720d (9/102=.), gen(pr_sz`welle')
   replace pr_sz`welle' = (pr_sz`welle'-1)/7
}

foreach welle of numlist 2/7 {
   recode kp`welle'_1660d (9/102=.), gen(pr_sz`welle')
   replace pr_sz`welle' = (pr_sz`welle'-1)/7
}


// taz

foreach welle of numlist 1 {
   recode kp`welle'_1720e (9/102=.), gen(pr_taz`welle')
   replace pr_taz`welle' = (pr_taz`welle'-1)/7
}

foreach welle of numlist 2/7 {
   recode kp`welle'_1660e (9/102=.), gen(pr_taz`welle')
   replace pr_taz`welle' = (pr_taz`welle'-1)/7
}


// Welt

foreach welle of numlist 1 {
   recode kp`welle'_1720f (9/102=.), gen(pr_welt`welle')
   replace pr_welt`welle' = (pr_welt`welle'-1)/7
}

foreach welle of numlist 2/7 {
   recode kp`welle'_1660f (9/102=.), gen(pr_welt`welle')
   replace pr_welt`welle' = (pr_welt`welle'-1)/7
}

tab pr_welt3


********************************************************************************
**
** Consumption of TV News
**
********************************************************************************


// ARD

foreach welle of numlist 1 {
   recode kp`welle'_1740a (9/102=.), gen(tv_ard`welle')
   replace tv_ard`welle' = (tv_ard`welle'-1)/7
}

foreach welle of numlist 2/7 {
   recode kp`welle'_1680a (9/102=.), gen(tv_ard`welle')
   replace tv_ard`welle' = (tv_ard`welle'-1)/7
}


// ZDF

foreach welle of numlist 1 {
   recode kp`welle'_1740b (9/102=.), gen(tv_zdf`welle')
   replace tv_zdf`welle' = (tv_zdf`welle'-1)/7
}

foreach welle of numlist 2/7 {
   recode kp`welle'_1680b (9/102=.), gen(tv_zdf`welle')
   replace tv_zdf`welle' = (tv_zdf`welle'-1)/7
}


// RTL

foreach welle of numlist 1 {
   recode kp`welle'_1740c (9/102=.), gen(tv_rtl`welle')
   replace tv_rtl`welle' = (tv_rtl`welle'-1)/7
}

foreach welle of numlist 2/7 {
   recode kp`welle'_1680c (9/102=.), gen(tv_rtl`welle')
   replace tv_rtl`welle' = (tv_rtl`welle'-1)/7
}


// SAT 1

foreach welle of numlist 1 {
   recode kp`welle'_1740d (9/102=.), gen(tv_sat`welle')
   replace tv_sat`welle' = (tv_sat`welle'-1)/7
}

foreach welle of numlist 2/7 {
   recode kp`welle'_1680d (9/102=.), gen(tv_sat`welle')
   replace tv_sat`welle' = (tv_sat`welle'-1)/7
}


// PRO 7

foreach welle of numlist 1 {
   recode kp`welle'_1740e (9/102=.), gen(tv_pro`welle')
   replace tv_pro`welle' = (tv_pro`welle'-1)/7
}

foreach welle of numlist 2/7 {
   recode kp`welle'_1680e (9/102=.), gen(tv_pro`welle')
   replace tv_pro`welle' = (tv_pro`welle'-1)/7
}


********************************************************************************
**
** Newsmagazines - Print
**
********************************************************************************


// Spiegel

foreach welle of numlist 1 {
   recode kp`welle'_1760a (99/102=.), gen(m_spgl`welle')
   replace m_spgl`welle' = (m_spgl`welle'-2)*-1
}

foreach welle of numlist 2/7 {
   recode kp`welle'_1700a (99/102=.), gen(m_spgl`welle')
   replace m_spgl`welle' = (m_spgl`welle'-2)*-1
}



// Focus

foreach welle of numlist 1 {
   recode kp`welle'_1760b (99/102=.), gen(m_fcus`welle')
   replace m_fcus`welle' = (m_fcus`welle'-2)*-1
}

foreach welle of numlist 2/7 {
   recode kp`welle'_1700b (99/102=.), gen(m_fcus`welle')
   replace m_fcus`welle' = (m_fcus`welle'-2)*-1
}


// Zeit

foreach welle of numlist 1 {
   recode kp`welle'_1760c (9/102=.), gen(m_zeit`welle')
   replace m_zeit`welle' = (m_zeit`welle'-2)*-1
}

foreach welle of numlist 2/7 {
   recode kp`welle'_1700c (9/102=.), gen(m_zeit`welle')
   replace m_zeit`welle' = (m_zeit`welle'-2)*-1
}


// Stern

foreach welle of numlist 1 {
   recode kp`welle'_1760d (9/102=.), gen(m_strn`welle')
   replace m_strn`welle' = (m_strn`welle'-2)*-1
}

foreach welle of numlist 2/7 {
   recode kp`welle'_1700d (9/102=.), gen(m_strn`welle')
   replace m_strn`welle' = (m_strn`welle'-2)*-1
}

tab m_strn5


********************************************************************************
**
** Political Internet Usage
**
********************************************************************************

tab kp2_1600
tab kp2_1600, nol

foreach welle of numlist 2/7 {
   recode kp`welle'_1600 (9/101=.), gen(i_nupol`welle')
   replace i_nupol`welle' = (i_nupol`welle'-1)/7
}

gen i_nupol1=i_nupol2
tab1 i_nupol?

********************************************************************************
**
** Indexes Media Consumption
**
********************************************************************************

* Daily Newspapers: 
/*
1. National papers, 
2. Bildzeitung,
3. other daily newspapers (mainly regional papers)
*/

forvalues num=1/7 {	
egen pr_paper`num' = rowtotal(pr_sz`num' pr_faz`num' pr_fr`num' ///
	pr_taz`num' pr_welt`num'), missing
replace pr_paper`num' = 1 if pr_paper`num'>1 & pr_paper`num'~=.
lab var pr_paper`num' "Daily paper"
}

tab1 pr_paper?

tab pr_bild1		//Bildzeitung already coded


gen pr_andz1=(kp1_1720g-1)/7 ///
	if kp1_1720g<=8
replace pr_andz1 = 0 if kp1_1720g==100
replace pr_andz1 = . if kp1_1720g==99

tab kp1_1720g pr_andz1, m


foreach wave of numlist 2/7 {
gen pr_andz`wave' = (kp`wave'_1660g-1)/7 ///
	if kp`wave'_1660g<=8
replace pr_andz`wave' = 0 if kp`wave'_1660g==100
replace pr_andz`wave' = . if kp`wave'_1660g==99
} 

tab kp2_1660g pr_andz2, m

mean pr_paper2 pr_bild2 pr_andz2  


* TV-News

foreach num of numlist 1/7 {
egen tv_oeff`num' = rowtotal(tv_ard`num' tv_zdf`num'), missing
replace tv_oeff`num' = 1 if tv_oeff`num'>1 & tv_oeff`num'!=.
lab var tv_oeff`num' "TV news (public)" 
}


forvalues num=1/7 {	
egen tv_privat`num' = rowtotal(tv_rtl`num' tv_sat`num'), missing
replace tv_privat`num' = 1 if tv_privat`num'>1 & tv_privat`num'!=.
lab var tv_privat`num' "TV news (private)" 
}

fre tv_oeff? tv_privat?

* Newsmagazines (Print)
/* Attention: Newsmagazines are only released once a week.
The index therefore shows how many different magazines were read in a given 
week. Max = 4*/


forvalues welle=1/7 {
egen m_gesamt`welle' = rowtotal(m_spgl`welle' m_fcus`welle' m_zeit`welle' ///
	m_strn`welle'), missing
gen m_gesamti`welle'= m_gesamt`welle'/4
lab var m_gesamt`welle' "Weekly paper" 
}

tab1 m_gesamt? m_gesamti?


*----------------------------------------------------------
* Use value from wave 2 in wave 1 for all media
*---------------------------------------------------------------

foreach stub in pr_bild pr_fr pr_faz pr_taz pr_welt pr_sz tv_ard tv_zdf ///
   tv_rtl tv_sat m_spgl m_fcus m_zeit m_strn {
      replace `stub'1 = `stub'2 if w1==1
}


********************************************************************************
**
** Talks about politics
**
********************************************************************************


tab kp1_1930
tab kp1_1930, nolabel
mvdecode kp?_1930, mv (99)
foreach welle of numlist 1/7 {
   gen gesprhin`welle' = kp`welle'_1930/7
   }



****************************************************************************
**	
** Party contacts
**
***************************************************************************

** Summary index over all party contacts

foreach welle of numlist 2/6 {			
egen pk_kundgebi`welle' = anycount(kp`welle'_420a_1 kp`welle'_420a_2 ///
 kp`welle'_420a_3 kp`welle'_420a_4 kp`welle'_420a_5), values(1)
replace pk_kundgebi`welle' = . if kp`welle'_400==99 | kp`welle'_400==.
gen pk_kundgebin`welle'=pk_kundgebi`welle'/5
egen pk_posti`welle' = anycount(kp`welle'_420c_1 kp`welle'_420c_2 ///
 kp`welle'_420c_3 kp`welle'_420c_4 kp`welle'_420c_5), values(1)
replace pk_posti`welle' = . if kp`welle'_400==99 | kp`welle'_400==.
gen pk_postin`welle'=pk_posti`welle'/5
egen pk_emaili`welle' = anycount(kp`welle'_420b_1 kp`welle'_420b_2 ///
 kp`welle'_420b_3 kp`welle'_420b_4 kp`welle'_420b_5), values(1)
replace pk_emaili`welle' = . if kp`welle'_400==99 | kp`welle'_400==.
gen pk_emailin`welle'=pk_emaili`welle'/5
egen pk_flumaili`welle' = rowmax(pk_posti`welle' pk_emaili`welle')
gen pk_flumailin`welle'=pk_flumaili`welle'/5
egen pk_tvspoti`welle' = anycount(kp`welle'_420d_1 kp`welle'_420d_2 ///
 kp`welle'_420d_3 kp`welle'_420d_4 kp`welle'_420d_5), values(1)
replace pk_tvspoti`welle' = . if kp`welle'_400==99 | kp`welle'_400==.
gen pk_tvspotin`welle'=pk_tvspoti`welle'/5
egen pk_radioi`welle' = anycount(kp`welle'_420e_1 kp`welle'_420e_2 ///
 kp`welle'_420e_3 kp`welle'_420e_4 kp`welle'_420e_5), values(1)
replace pk_radioi`welle' = . if kp`welle'_400==99 | kp`welle'_400==.
gen pk_radioin`welle'=pk_radioi`welle'/5
egen pk_plakati`welle' = anycount(kp`welle'_420g_1 kp`welle'_420g_2 ///
 kp`welle'_420g_3 kp`welle'_420g_4 kp`welle'_420g_5), values(1)
replace pk_plakati`welle' = . if kp`welle'_400==99 | kp`welle'_400==.
gen pk_plakatin`welle'=pk_plakati`welle'/5
egen pk_standi`welle' = anycount(kp`welle'_420h_1 kp`welle'_420h_2 ///
 kp`welle'_420h_3 kp`welle'_420h_4 kp`welle'_420h_5), values(1)
replace pk_standi`welle' = . if kp`welle'_400==99 | kp`welle'_400==.
gen pk_standin`welle'=pk_standi`welle'/5
egen pk_websitei`welle' = anycount(kp`welle'_420k_1 kp`welle'_420k_2 ///
 kp`welle'_420k_3 kp`welle'_420k_4 kp`welle'_420k_5), values(1)
replace pk_websitei`welle' = . if kp`welle'_400==99 | kp`welle'_400==.
gen pk_websitein`welle'=pk_websitei`welle'/5
egen pk_gesamti`welle' = rowtotal(pk_kundgebi`welle' pk_flumaili`welle' ///
	pk_tvspoti`welle' pk_radioi`welle' pk_plakati`welle' pk_standi`welle' ///
	pk_websitei`welle'), missing
gen pk_gesamtino`welle'=pk_gesamti`welle'/35
}

foreach welle in 7 {			
egen pk_kundgebi`welle' = anycount(kp`welle'_420a_1 kp`welle'_420a_2 ///
 kp`welle'_420a_3 kp`welle'_420a_4 kp`welle'_420a_5), values(1)
replace pk_kundgebi`welle' = . if kp`welle'_401==99 | kp`welle'_401==.
gen pk_kundgebin`welle'=pk_kundgebi`welle'/5
egen pk_posti`welle' = anycount(kp`welle'_420c_1 kp`welle'_420c_2 ///
 kp`welle'_420c_3 kp`welle'_420c_4 kp`welle'_420c_5), values(1)
replace pk_posti`welle' = . if kp`welle'_401==99 | kp`welle'_401==.
gen pk_postin`welle'=pk_posti`welle'/5
egen pk_emaili`welle' = anycount(kp`welle'_420b_1 kp`welle'_420b_2 ///
 kp`welle'_420b_3 kp`welle'_420b_4 kp`welle'_420b_5), values(1)
replace pk_emaili`welle' = . if kp`welle'_401==99 | kp`welle'_401==.
gen pk_emailin`welle'=pk_emaili`welle'/5
egen pk_flumaili`welle' = rowmax(pk_posti`welle' pk_emaili`welle')
gen pk_flumailin`welle'=pk_flumaili`welle'/5
egen pk_tvspoti`welle' = anycount(kp`welle'_420d_1 kp`welle'_420d_2 ///
 kp`welle'_420d_3 kp`welle'_420d_4 kp`welle'_420d_5), values(1)
replace pk_tvspoti`welle' = . if kp`welle'_401==99 | kp`welle'_401==.
gen pk_tvspotin`welle'=pk_tvspoti`welle'/5
egen pk_radioi`welle' = anycount(kp`welle'_420e_1 kp`welle'_420e_2 ///
 kp`welle'_420e_3 kp`welle'_420e_4 kp`welle'_420e_5), values(1)
replace pk_radioi`welle' = . if kp`welle'_401==99 | kp`welle'_401==.
gen pk_radioin`welle'=pk_radioi`welle'/5
egen pk_plakati`welle' = anycount(kp`welle'_420g_1 kp`welle'_420g_2 ///
 kp`welle'_420g_3 kp`welle'_420g_4 kp`welle'_420g_5), values(1)
replace pk_plakati`welle' = . if kp`welle'_401==99 | kp`welle'_401==.
gen pk_plakatin`welle'=pk_plakati`welle'/5
egen pk_standi`welle' = anycount(kp`welle'_420h_1 kp`welle'_420h_2 ///
 kp`welle'_420h_3 kp`welle'_420h_4 kp`welle'_420h_5), values(1)
replace pk_standi`welle' = . if kp`welle'_401==99 | kp`welle'_401==.
gen pk_standin`welle'=pk_standi`welle'/5
egen pk_websitei`welle' = anycount(kp`welle'_420k_1 kp`welle'_420k_2 ///
 kp`welle'_420k_3 kp`welle'_420k_4 kp`welle'_420k_5), values(1)
replace pk_websitei`welle' = . if kp`welle'_401==99 | kp`welle'_401==.
gen pk_websitein`welle'=pk_websitei`welle'/5
egen pk_gesamti`welle' = rowtotal(pk_kundgebi`welle' pk_flumaili`welle' ///
	pk_tvspoti`welle' pk_radioi`welle' pk_plakati`welle' pk_standi`welle' ///
	pk_websitei`welle'), missing
gen pk_gesamtino`welle'=pk_gesamti`welle'/35
}


gen pk_gesamtino1 = pk_gesamtino2
replace pk_gesamtino7 = pk_gesamtino6


*----------------------------------
* Save
*------------------------------------

keep lfdn m_gesamti? tv_privat? tv_oeff? pr_andz? pr_paper? pr_bild? ///
	pk_gesamtino? i_nupol? gesprhin? watcheddebate*
	
save "${path}\Reproducible Do-Files\Chapter 5\Data\komm_variablen09.dta", replace	
